﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.AnimalFight.Lib;
using Cspl.AnimalFight.Lib.Data;

namespace Cspl.AnimalFight.Main
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BattleField battleField = new BattleField();
            
            Dog dog1 = new Dog
            {
                Name = "Doggy",
                HP = 1000,
                DP = 100,
                AP = 300,
                Mood = DogMood.Good
            };

            Dog dog2 = new Dog
            {
                Name = "Snoopy",
                HP = 1000,
                DP = 250,
                AP = 250,
                Mood = DogMood.Bad
            };

            Duck duck1 = new Duck
            {
                Name = "Donal",
                HP = 1000,
                DP = 200,
                AP = 100,
            };

            Duck duck2 = new Duck
            {
                Name = "Gober",
                HP = 1000,
                DP = 150,
                AP = 300,
            };

            Snake snake1 = new Snake
            {
                Name = "Snake",
                HP = 1000,
                DP = 50,
                AP = 300,
            };

            Snake snake2 = new Snake
            {
                Name = "Sanca",
                HP = 1000,
                DP = 100,
                AP = 250,
            };

            Horse horse1 = new Horse
            {
                Name = "Makibao",
                HP = 1000,
                DP = 200,
                AP = 200,
            };

            Horse horse2 = new Horse 
            {
                Name = "Ponny",
                HP = 1000,
                DP = 150,
                AP = 250,
            };

            battleField[dog1.Name] = dog1;
            battleField[dog2.Name] = dog2;
            battleField[snake1.Name] = snake1;
            battleField[snake2.Name] = snake2;
            battleField[horse1.Name] = horse1;
            battleField[horse2.Name] = horse2;
            battleField[duck1.Name] = duck1;
            battleField[duck2.Name] = duck2;
           
            //battleField.Command("Doggy", Commands.Attack, "Snake");
            Console.WriteLine("======================= Animal Fight Application =======================");
            Console.WriteLine("  Use Attack, Defend, Escape, Return and Status to run the application. ");
            Console.WriteLine("\t\t\trowdua , Q1 2013");
            Console.WriteLine("------------------------------------------------------------------------\n");
            Console.WriteLine("Need for Help? Use Help or h for information");
            string commandLine;
            string command = string.Empty;
            while (command != "Exit" && command != "x")
            {
                commandLine = System.Console.ReadLine();
                string[] commands = commandLine.Split(' ');
                command = commands[0];
                switch (command.ToUpper())
                {
                    case "ADD":
                        if (commands.Length < 6)
                        {
                            Console.WriteLine("  Invalid command for add animal.");
                        }
                        else
                        {
                            try
                            {
                                battleField.addAnimal(commands[1], commands[2], Convert.ToInt32(commands[3]), Convert.ToInt32(commands[4]), Convert.ToInt32(commands[5]));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("  Please make sure you are input integer number for all power."); ;
                            }                           
                        }
                        break;

                    case "UPGRADE":
                        if (commands.Length < 4)
                        {
                            Console.WriteLine("  Invalid command for add animal.");
                        }
                        else
                        {
                            try
                            {
                                battleField.upgradePower(commands[1], commands[2], commands[3]);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("  Please make sure your input value."); ;
                            }
                        }
                        break;

                    case "ATTACK":
                        if (commands.Length < 3)
                        {
                            Console.WriteLine("  Invalid command for attack.");
                        }
                        else
                        {
                            battleField.Command(commands[1], Commands.Attack, commands[2]);
                        }
                        break;

                    case "DEFEND":
                        if (commands.Length < 2)
                        {
                            Console.WriteLine("  Invalid command for defend.");
                        }
                        else
                        {
                            battleField.Command(commands[1], Commands.Defend, string.Empty);
                        }
                        break;

                    case "ESCAPE":
                        if (commands.Length < 2)
                        {
                            Console.WriteLine("  Invalid command for escape.");
                        }
                        else
                        {
                            battleField.Command(commands[1], Commands.Escape, string.Empty);
                        }
                        break;

                    case "RETURN":
                        if (commands.Length < 2)
                        {
                            Console.WriteLine("  Invalid command for return.");
                        }
                        else
                        {
                            battleField.Command(commands[1], Commands.Return, string.Empty);
                        }
                        break;

                    case "STATUS":
                        battleField.AnimalStatus();
                        break;

                    case "S":
                        battleField.AnimalStatus();
                        break;

                    case "HELP":
                        battleField.displayCommand();
                        break;

                    case "H":
                        battleField.displayCommand();
                        break;

                    case "Exit":
                        Console.WriteLine("  Exit the application.");
                        break;

                    case "X":
                        Console.WriteLine("  Exit the application.");
                        break;

                    default:
                        Console.WriteLine("  Invalid command.");
                        break;
                }
            }
        }
    }
}
